<?php

namespace app\Modules\Admin\controllers;

use Yii;
use app\models\Showpic;
use yii\web\Controller;
use yii\web\UploadedFile;
use app\models\UploadForm;
use app\filters\Json;

/**
 * BannerController implements the CRUD actions for Banner model.
 */
class ShowpicController extends Controller
{
    public function behaviors()
    {
        return [
            [
                'class' => Json::className(),
            ]
        ];
    }

    public function actionCreate()
    {
        $model = new Showpic();
        $uploadForm = new UploadForm();
        if(Yii::$app->request->isPost){
            $uploadForm->file = UploadedFile::getInstance($uploadForm, 'file');
            if (($model->url = $uploadForm->upload())&&$model->load(Yii::$app->request->post()) && $model->save()) {
                $showpics = Showpic::find()
                    ->where(['auction_id' => $model->auction_id, 'show_id' => 0])
                    ->asArray()
                    ->all();
                $data = ['showpics'=>$showpics];
                return Json::success($data);
            }

        }
        return Json::error(Yii::$app->request->post());
    }
}